from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-05 14:03:49.335539
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 05, Jul, 2022
Time: 14:03:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6960
Nobs: 708.000 HQIC: -50.0519
Log likelihood: 8846.20 FPE: 1.46369e-22
AIC: -50.2759 Det(Omega_mle): 1.29011e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298718 0.057486 5.196 0.000
L1.Burgenland 0.106349 0.037766 2.816 0.005
L1.Kärnten -0.109466 0.020004 -5.472 0.000
L1.Niederösterreich 0.211431 0.078900 2.680 0.007
L1.Oberösterreich 0.104921 0.077246 1.358 0.174
L1.Salzburg 0.256751 0.040388 6.357 0.000
L1.Steiermark 0.045344 0.052618 0.862 0.389
L1.Tirol 0.109310 0.042717 2.559 0.010
L1.Vorarlberg -0.058704 0.037040 -1.585 0.113
L1.Wien 0.040698 0.068331 0.596 0.551
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048520 0.120434 0.403 0.687
L1.Burgenland -0.034228 0.079121 -0.433 0.665
L1.Kärnten 0.041109 0.041909 0.981 0.327
L1.Niederösterreich -0.167845 0.165297 -1.015 0.310
L1.Oberösterreich 0.424212 0.161832 2.621 0.009
L1.Salzburg 0.288410 0.084614 3.409 0.001
L1.Steiermark 0.100817 0.110237 0.915 0.360
L1.Tirol 0.319061 0.089494 3.565 0.000
L1.Vorarlberg 0.027777 0.077600 0.358 0.720
L1.Wien -0.040401 0.143154 -0.282 0.778
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187466 0.029420 6.372 0.000
L1.Burgenland 0.090242 0.019328 4.669 0.000
L1.Kärnten -0.008032 0.010238 -0.785 0.433
L1.Niederösterreich 0.265124 0.040379 6.566 0.000
L1.Oberösterreich 0.138064 0.039533 3.492 0.000
L1.Salzburg 0.045941 0.020670 2.223 0.026
L1.Steiermark 0.019735 0.026929 0.733 0.464
L1.Tirol 0.091707 0.021862 4.195 0.000
L1.Vorarlberg 0.056799 0.018956 2.996 0.003
L1.Wien 0.114191 0.034970 3.265 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111686 0.029925 3.732 0.000
L1.Burgenland 0.045334 0.019659 2.306 0.021
L1.Kärnten -0.013707 0.010413 -1.316 0.188
L1.Niederösterreich 0.192115 0.041072 4.678 0.000
L1.Oberösterreich 0.302473 0.040211 7.522 0.000
L1.Salzburg 0.108126 0.021024 5.143 0.000
L1.Steiermark 0.104915 0.027391 3.830 0.000
L1.Tirol 0.103705 0.022237 4.664 0.000
L1.Vorarlberg 0.067500 0.019281 3.501 0.000
L1.Wien -0.022825 0.035570 -0.642 0.521
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134608 0.054590 2.466 0.014
L1.Burgenland -0.051706 0.035864 -1.442 0.149
L1.Kärnten -0.044353 0.018997 -2.335 0.020
L1.Niederösterreich 0.157149 0.074926 2.097 0.036
L1.Oberösterreich 0.139306 0.073355 1.899 0.058
L1.Salzburg 0.286633 0.038354 7.473 0.000
L1.Steiermark 0.047646 0.049968 0.954 0.340
L1.Tirol 0.166954 0.040566 4.116 0.000
L1.Vorarlberg 0.093053 0.035174 2.645 0.008
L1.Wien 0.072998 0.064889 1.125 0.261
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055253 0.043420 1.273 0.203
L1.Burgenland 0.037619 0.028526 1.319 0.187
L1.Kärnten 0.051065 0.015110 3.380 0.001
L1.Niederösterreich 0.217985 0.059595 3.658 0.000
L1.Oberösterreich 0.294332 0.058346 5.045 0.000
L1.Salzburg 0.047789 0.030506 1.567 0.117
L1.Steiermark 0.001695 0.039744 0.043 0.966
L1.Tirol 0.140796 0.032265 4.364 0.000
L1.Vorarlberg 0.073882 0.027977 2.641 0.008
L1.Wien 0.080412 0.051612 1.558 0.119
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175395 0.051923 3.378 0.001
L1.Burgenland -0.002535 0.034112 -0.074 0.941
L1.Kärnten -0.063002 0.018069 -3.487 0.000
L1.Niederösterreich -0.081414 0.071266 -1.142 0.253
L1.Oberösterreich 0.194600 0.069772 2.789 0.005
L1.Salzburg 0.056553 0.036480 1.550 0.121
L1.Steiermark 0.236332 0.047527 4.973 0.000
L1.Tirol 0.497486 0.038584 12.894 0.000
L1.Vorarlberg 0.044739 0.033456 1.337 0.181
L1.Wien -0.055610 0.061719 -0.901 0.368
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170441 0.059279 2.875 0.004
L1.Burgenland -0.012009 0.038944 -0.308 0.758
L1.Kärnten 0.063754 0.020628 3.091 0.002
L1.Niederösterreich 0.209132 0.081361 2.570 0.010
L1.Oberösterreich -0.076754 0.079655 -0.964 0.335
L1.Salzburg 0.212716 0.041648 5.107 0.000
L1.Steiermark 0.124884 0.054260 2.302 0.021
L1.Tirol 0.068139 0.044050 1.547 0.122
L1.Vorarlberg 0.119218 0.038195 3.121 0.002
L1.Wien 0.122762 0.070462 1.742 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363085 0.034233 10.606 0.000
L1.Burgenland 0.007342 0.022490 0.326 0.744
L1.Kärnten -0.023718 0.011913 -1.991 0.046
L1.Niederösterreich 0.215670 0.046985 4.590 0.000
L1.Oberösterreich 0.204984 0.046000 4.456 0.000
L1.Salzburg 0.043525 0.024051 1.810 0.070
L1.Steiermark -0.014640 0.031334 -0.467 0.640
L1.Tirol 0.105848 0.025438 4.161 0.000
L1.Vorarlberg 0.069441 0.022057 3.148 0.002
L1.Wien 0.030850 0.040691 0.758 0.448
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037531 0.138459 0.194112 0.155559 0.115549 0.102087 0.059112 0.216749
Kärnten 0.037531 1.000000 -0.015629 0.134309 0.055962 0.095255 0.435662 -0.052992 0.093160
Niederösterreich 0.138459 -0.015629 1.000000 0.335054 0.141257 0.294356 0.092221 0.177718 0.311582
Oberösterreich 0.194112 0.134309 0.335054 1.000000 0.226840 0.324714 0.176174 0.164016 0.263758
Salzburg 0.155559 0.055962 0.141257 0.226840 1.000000 0.138115 0.116424 0.138889 0.129447
Steiermark 0.115549 0.095255 0.294356 0.324714 0.138115 1.000000 0.145343 0.130926 0.072307
Tirol 0.102087 0.435662 0.092221 0.176174 0.116424 0.145343 1.000000 0.111439 0.141993
Vorarlberg 0.059112 -0.052992 0.177718 0.164016 0.138889 0.130926 0.111439 1.000000 0.001136
Wien 0.216749 0.093160 0.311582 0.263758 0.129447 0.072307 0.141993 0.001136 1.000000